package 力扣日常刷题.木22二月.第01天206;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 */
public class Demo04JZ二维数组中的查找 {

    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int n = matrix.length,m = matrix[0].length;
        // x 纵    y 横
        int x = n,y = m;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y && y > 0; j++) {
                if(matrix[i][j] == target)return true;
                else if(matrix[i][j] > target) y = j ;
            }
        }
        return false;
    }


}
